<!doctype html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>登录页面</title>
    <link rel="stylesheet" href="/home/css/index.css">
    <script src="/home/js/jquery.1.11.1.min.js"></script>
    <style>

    </style>

</head>

<body>
<div class="register_head_on">

</div>
<div class="register_head">
    <a href="../index.html"><img src="/home/img/logo.jpg" alt=""></a>
    <div class="register_head_right">
        <p class="register_head_right_p1">工 业 商 城</p>
        <p class="register_head_right_p2">让工业商品和物料便捷</p>
    </div>

</div>
<form id="login_from" method="post">
    <div class="register">
        <div class="register_boby">
            <div class="register_boby_min">
                <div class="register_boby_no1">
                    <div class="register_boby_no1_in">
                        <span style="color: #ff6700">账号登录 </span>
                        <span class="register_boby_sapn"> | </span>
                        <span> 扫码登录</span>
                    </div>
                </div>
                <div class="register_boby_no2">
                    <input type="text" id="phone" name="phone" placeholder="手机号码">
                    <input type="password" id="password" name="password" placeholder="密码">
                    <div class="register_boby_no2_div">
                        <button type="button" id="submit-btn">登录</button>
                    </div>
                </div>
                <div class="register_boby_no3">
                    <a href="javascript:void(0);" style="color: #ff6700">手机短信登录/注册</a>
                    <sapn class="register_boby_no3_span">
                        <a href="/home/avascript:void(0);">立即注册</a>
                        <span>|</span>
                        <a href="/home/avascript:void(0);">忘记密码?</a>
                    </sapn>

                </div>
                <div class="register_boby_no4">
                    <img src="/home/img/register02.jpg" alt="">
                </div>


            </div>
        </div>
    </div>
</form>
<div class="register_foot">
    <img src="/home/img/register03.jpg" alt="">
</div>

<script>
    $(document).ready(function () {
        $("#submit-btn").click(function () {
            var phone = $("#phone").val();
            var password = $("#password").val();
            var currentPath = window.location.pathname;
            console.log(currentPath)
            /*表单提交前整体校验，验证通过提交表单，验证失败不提交*/
            $.ajax({
                url: '/login',
                type: 'POST',
                dataType: 'json',
                data: {phone: phone, password: password, currentPath: currentPath},
                success: function (response) {
                    console.log(response)
                    if (response.code !== "0") {
                        alert(response.message)
                    }
                    if (response.code === "0" || response.message === "用户已登录") {
                        window.location.href = '/index.html'
                    }
                },
            });
        });
    });
</script>
</body>

</html>